package puyu.manage.service.constant;

import org.springframework.stereotype.Component;
import puyu.manage.service.utils.MessageUtils;
import puyu.manage.service.utils.StringUtils;

import java.util.HashMap;
/**
 *  @ClassName: 处理鉴权报错的工具类
 *  @author: whl
 *  @Date: 2024/6/2 22:58
 *  @Description: Description of this class
 */
@Component
public class AjaxResult extends HashMap<String, Object> {
    public static final String CODE_TAG = "code";
    public static final String MSG_TAG = "msg";
    public static final String DATA_TAG = "data";

    public AjaxResult() {
    }

    public AjaxResult(int code, String msg) {
        super.put("code", code);
        super.put("msg", msg);
    }

    public AjaxResult(int code, String msg, Object data) {
        super.put("code", code);
        super.put("msg", msg);
        if (StringUtils.isNotNull(data)) {
            super.put("data", data);
        }

    }

    public static AjaxResult success() {
        return success(MessageUtils.message("00000", new Object[0]));
    }

    public static AjaxResult success(Object data) {
        return success(MessageUtils.message("00000", new Object[0]), data);
    }

    public static AjaxResult success(String msg) {
        return success(msg, (Object)null);
    }

    public static AjaxResult successMsg(String msg) {
        return success(MessageUtils.message("00000", new Object[0]), msg);
    }

    public static AjaxResult success(String msg, Object data) {
        return new AjaxResult(200, msg, data);
    }

    public static AjaxResult error() {
        return error(MessageUtils.message("00001", new Object[0]));
    }

    public static AjaxResult error(String msg) {
        return error(msg, (Object)null);
    }

    public static AjaxResult error(String msg, Object data) {
        return new AjaxResult(500, msg, data);
    }

    public static AjaxResult error(int code, String msg) {
        return new AjaxResult(code, msg, (Object)null);
    }

    public static AjaxResult custom(String msg) {
        return new AjaxResult(500, msg);
    }
}
